// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
/**
 * @summary Initializes an accordion list with more than one section that will have its display toggled by invoking an interaction on the summary title
 *
 * @name base
 * @selector .slds-accordion
 * @restrict ul
 * @variant
 * @support dev-ready
 */
.slds-accordion {
  position: relative;
}

/**
 * @summary List item for each accordion section
 * @selector .slds-accordion__list-item
 * @restrict .slds-accordion li
 */
.slds-accordion__list-item {
  border-top-width: var(--slds-c-accordion-section-sizing-border, var(--slds-c-accordion-sizing-border, var(--sds-c-accordion-sizing-border, $border-width-thin)));
  border-top-style: solid;
  border-top-color: var(--slds-c-accordion-section-color-border, var(--slds-c-accordion-color-border, var(--sds-c-accordion-color-border, var(--slds-g-color-border-base-1, #{$color-border}))));

  &:first-child {
    border-top: 0;
  }
}

/**
 * @summary Summary title for each expandable panel inside of an accordion
 * @selector .slds-accordion__summary
 * @restrict .slds-accordion__section div
 */
.slds-accordion__summary {
  /**
   * This is specific to the margin properties below as a workaround to address an issue with the parser in production.
   * (Having 5 or more arguments breaks the parser)
   *
   * We tried alternatives (e.g., mixin), but the `scss-parser-aura` could not resolve the old fallback tokens.
   * See:
   * - Mixin workaround that did not work: https://github.com/salesforce-ux/design-system-internal/pull/5398
   * - Bug report: https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07EE000025IvUEYA0/view
   */
  --_slds-c-accordion-section-spacing-block-start-deprecated: var(
    --slds-c-accordion-section-spacing-blockstart,
    var(--sds-c-accordion-section-spacing-block-start)
  );
  --_slds-c-accordion-section-spacing-inline-end-deprecated: var(
    --slds-c-accordion-section-spacing-inlineend,
    var(--sds-c-accordion-section-spacing-inline-end)
  );
  --_slds-c-accordion-section-spacing-block-end-deprecated: var(
    --slds-c-accordion-section-spacing-blockend,
    var(--sds-c-accordion-section-spacing-block-end)
  );
  --_slds-c-accordion-section-spacing-inline-start-deprecated: var(
    --slds-c-accordion-section-spacing-inlinestart,
    var(--sds-c-accordion-section-spacing-inline-start)
  );

  display: flex;
  margin-top: calc(
    var(
        --slds-c-accordion-section-spacing-block-start,
        var(
          --_slds-c-accordion-section-spacing-block-start-deprecated,
          #{$spacing-small}
        )
      ) * -1
  );
  margin-right: calc(
    var(
        --slds-c-accordion-section-spacing-inline-end,
        var(
          --_slds-c-accordion-section-spacing-inline-end-deprecated,
          #{$spacing-small}
        )
      ) * -1
  );
  margin-bottom: calc(
    var(
        --slds-c-accordion-section-spacing-block-end,
        var(
          --_slds-c-accordion-section-spacing-block-end-deprecated,
          #{$spacing-small}
        )
      ) * -1
  );
  margin-left: calc(
    var(
        --slds-c-accordion-section-spacing-inline-start,
        var(
          --_slds-c-accordion-section-spacing-inline-start-deprecated,
          #{$spacing-small}
        )
      ) * -1
  );
  padding-top: var(
    --slds-c-accordion-section-spacing-block-start,
    var(
      --slds-c-accordion-section-spacing-blockstart,
      var(--sds-c-accordion-section-spacing-block-start, #{$spacing-small})
    )
  );
  padding-right: var(
    --slds-c-accordion-section-spacing-inline-end,
    var(
      --slds-c-accordion-section-spacing-inlineend,
      var(--sds-c-accordion-section-spacing-inline-end, #{$spacing-small})
    )
  );
  padding-bottom: var(
    --slds-c-accordion-section-spacing-block-end,
    var(
      --slds-c-accordion-section-spacing-blockend,
      var(--sds-c-accordion-section-spacing-block-end, #{$spacing-small})
    )
  );
  padding-left: var(
    --slds-c-accordion-section-spacing-inline-start,
    var(
      --slds-c-accordion-section-spacing-inlinestart,
      var(--sds-c-accordion-section-spacing-inline-start, #{$spacing-small})
    )
  );
  background-color: var(
    --slds-c-accordion-summary-color-background,
    var(--sds-c-accordion-summary-color-background, transparent)
  );

  // For Action Overflow Menu variant
  .slds-dropdown-trigger .slds-button {
    margin-left: $spacing-small;
  }
}

/**
 * @summary Summary title for each expandable panel inside of an accordion
 * @selector .slds-accordion__summary-heading
 * @restrict .slds-accordion__section h2
 */
.slds-accordion__summary-heading {
  display: flex;
  flex-grow: 1;
  min-width: 0;
  color: var(--slds-c-accordion-heading-color, var(--slds-c-accordion-heading-text-color, var(--sds-c-accordion-heading-text-color,
  var(--slds-g-color-neutral-base-10, #{$color-text-default}))));
  font-size: var(--slds-c-accordion-heading-font-size, var(--sds-c-accordion-heading-font-size, $var-font-size-5));
  line-height: var(--slds-c-accordion-heading-line-height, var(--slds-c-accordion-heading-font-lineheight, var(--sds-c-accordion-heading-line-height, $line-height-heading)));

  .slds-button:focus {
    box-shadow: inset var(--slds-g-shadow-outline-focus-1);
  }
}

/**
 * @summary Actionable button inside of accordion summary that would toggle the visibility of each section
 * @selector .slds-accordion__summary-action
 * @restrict .slds-accordion__summary button
 */
.slds-accordion__summary-action {
  /**
   * This is specific to the margin properties below as a workaround to address an issue with the parser in production.
   * (Having 5 or more arguments breaks the parser)
   *
   * We tried alternatives (e.g., mixin), but the `scss-parser-aura` could not resolve the old fallback tokens.
   * See:
   * - Mixin workaround that did not work: https://github.com/salesforce-ux/design-system-internal/pull/5398
   * - Bug report: https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07EE000025IvUEYA0/view
   */
  --_slds-c-accordion-section-spacing-block-start-deprecated: var(
    --slds-c-accordion-section-spacing-blockstart,
    var(--sds-c-accordion-section-spacing-block-start)
  );
  --_slds-c-accordion-section-spacing-inline-end-deprecated: var(
    --slds-c-accordion-section-spacing-inlineend,
    var(--sds-c-accordion-section-spacing-inline-end)
  );
  --_slds-c-accordion-section-spacing-block-end-deprecated: var(
    --slds-c-accordion-section-spacing-blockend,
    var(--sds-c-accordion-section-spacing-block-end)
  );
  --_slds-c-accordion-section-spacing-inline-start-deprecated: var(
    --slds-c-accordion-section-spacing-inlinestart,
    var(--sds-c-accordion-section-spacing-inline-start)
  );

  display: inline-flex;
  flex-grow: 1;
  align-items: center;
  min-width: 0;
  margin-top: calc(
    var(
        --slds-c-accordion-section-spacing-block-start,
        var(
          --_slds-c-accordion-section-spacing-block-start-deprecated,
          #{$spacing-small}
        )
      ) * -1
  );
  margin-right: calc(
    var(
        --slds-c-accordion-section-spacing-inline-end,
        var(
          --_slds-c-accordion-section-spacing-inline-end-deprecated,
          #{$spacing-small}
        )
      ) * -1
  );
  margin-bottom: calc(
    var(
        --slds-c-accordion-section-spacing-block-end,
        var(
          --_slds-c-accordion-section-spacing-block-end-deprecated,
          #{$spacing-small}
        )
      ) * -1
  );
  margin-left: calc(
    var(
        --slds-c-accordion-section-spacing-inline-start,
        var(
          --_slds-c-accordion-section-spacing-inline-start-deprecated,
          #{$spacing-small}
        )
      ) * -1
  );
  padding-top: var(
    --slds-c-accordion-section-spacing-block-start,
    var(
      --slds-c-accordion-section-spacing-blockstart,
      var(--sds-c-accordion-section-spacing-block-start, $spacing-small)
    )
  );
  padding-right: var(
    --slds-c-accordion-section-spacing-inline-end,
    var(
      --slds-c-accordion-section-spacing-inlineend,
      var(--sds-c-accordion-section-spacing-inline-end, $spacing-small)
    )
  );
  padding-bottom: var(
    --slds-c-accordion-section-spacing-block-end,
    var(
      --slds-c-accordion-section-spacing-blockend,
      var(--sds-c-accordion-section-spacing-block-end, $spacing-small)
    )
  );
  padding-left: var(
    --slds-c-accordion-section-spacing-inline-start,
    var(
      --slds-c-accordion-section-spacing-inlinestart,
      var(--sds-c-accordion-section-spacing-inline-start, $spacing-small)
    )
  );

  &:hover,
  &:focus {
    color: var(--slds-c-accordion-heading-text-color-hover, var(--sds-c-accordion-heading-text-color-hover, $brand-accessible-active));
  }
}

/**
 * @summary Icon inside of actionable button within an accordion section
 * @selector .slds-accordion__summary-action-icon
 * @restrict .slds-accordion__summary-action svg
 */
.slds-accordion__summary-action-icon {
  flex-shrink: 0;
  transform: rotate(-90deg);

  @include rtl() {
    transform: rotate(90deg);
  }
}

/**
 * @summary Text of summary title for each expandable panel inside of an accordion
 * @selector .slds-accordion__summary-content
 * @restrict .slds-accordion__summary-action span
 */
.slds-accordion__summary-content {
  @include mq-large-min {
    @include truncate;
  }
}

/**
 * @summary Each expandable panel inside of an accordion
 * @selector .slds-accordion__section
 * @restrict .slds-accordion section
 */
.slds-accordion__section {
  padding-top: var(--slds-c-accordion-section-spacing-block-start, var(--slds-c-accordion-section-spacing-blockstart, var(--sds-c-accordion-section-spacing-block-start, $spacing-small)));
  padding-right: var(--slds-c-accordion-section-spacing-inline-end, var(--slds-c-accordion-section-spacing-inlineend, var(--sds-c-accordion-section-spacing-inline-end, $spacing-small)));
  padding-bottom: var(--slds-c-accordion-section-spacing-block-end, var(--slds-c-accordion-section-spacing-blockend, var(--sds-c-accordion-section-spacing-block-end, $spacing-small)));
  padding-left: var(--slds-c-accordion-section-spacing-inline-start, var(--slds-c-accordion-section-spacing-inlinestart, var(--sds-c-accordion-section-spacing-inline-start, $spacing-small)));
}

/**
 * @summary Each expandable panel inside of an accordion
 * @selector .slds-accordion__content
 * @restrict .slds-accordion__section div
 */
.slds-accordion__content {
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  height: 0;
}

/**
 * @name toggle section
 * @summary Toggle visibility of accordion section + rotate icon
 * @selector .slds-is-open
 * @restrict .slds-accordion__section
 * @modifier
 * @group visibility
 */
.slds-is-open {

  > .slds-accordion__summary {
    margin-bottom: 0;

    .slds-accordion__summary-action-icon {
      transform: rotate(0deg);
    }
  }

  > .slds-accordion__content {
    overflow: visible;
    visibility: visible;
    opacity: 1;
    height: auto;
  }
}
